<template>
	<el-main>
		<!-- 列表 -->
		<el-table
		  :data="tableData"
		  style="width: 90%">
		  <el-table-column
		  label="#" prop="id"
		  ></el-table-column>

		  <el-table-column
			prop="mingcheng"
			label="合同名称">
		  </el-table-column>
			<el-table-column
					label="合同编码">
				<template slot-scope="scope">
					<div v-html="scope.row.htmlFile"></div>
				</template>
			</el-table-column>
		  
		  <el-table-column label="创建时间" prop="addShijian">
		  </el-table-column>
		  <!-- 分页 -->
		  <el-table-column label="操作">
			  <template slot-scope="scope">
				  <el-button size="mini" @click="edit(scope.row.id)">编辑</el-button>
				  <el-button size="mini" @click="openCheck(scope.row.id)">审核</el-button>
				  <el-button size="mini" @click="createPdf(scope.row.id)">生成合同</el-button>
				  <el-button size="mini" @click="previewPdf(scope.row.id)">预览合同</el-button>
				  <el-button size="mini" @click="download(scope.row)">下载合同</el-button>
			  </template>
		  </el-table-column>

		</el-table>

		<div>
			<el-button size="mini" @click="add">添加</el-button>
		</div>


		<el-dialog title="审核" :visible.sync="dialogFormVisible">
			<el-form :model="form">
				<el-form-item label="请选择" label-width="100px;">
					<el-select v-model="form.isCheck" placeholder="请选择">
						<el-option label="通过" value="1">通过</el-option>
						<el-option label="不通过" value="0">不通过</el-option>
					</el-select>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dialogFormVisible = false">取 消</el-button>
				<el-button type="primary" @click="check()">确 定</el-button>
			</div>
		</el-dialog>

	</el-main>
</template>

<script>
	export default {
		data(){
			return {

				tableData:[

				],
				queryForm:{
					pageNum:1,
					pageSize:300
				},
				checkId:null,
				dialogFormVisible:false,
				form:{
					id:null,
					isCheck:1
				}
			}
		},
		methods:{
			openCheck(id) {
				this.form.id=id;
				this.dialogFormVisible=true;
			},
			check() {
				this.dialogFormVisible=false;
				this.axios.get(this.$baseUrl+"hetong/check",{params:this.form}).then(res=>{
					if (res.data.result) {
						this.$message.success("审核成功");
						this.list();
					}else {
						this.$message.error(res.data.message);
					}
				})
			},
			createPdf(id) {
				// debugger
				this.axios.post(this.$baseUrl+"hetong/createPdf",{id:id}).then(res=>{
					if (res.data.result) {
						this.$message.success("生成合同成功");
					}
				})
			},
			previewPdf(id) {
				this.axios.get(this.$baseUrl+"hetong/previewPdf",{params:{id:id}}).then(res=>{
					if (res.data.result) {
						window.open(res.data.data);
					}
				})
			},
			download(row) {
				window.open("http://localhost:1000/hetong/download?id="+row.id+"&mingcheng="+row.mingcheng);
				/*this.axios.get(this.$baseUrl+"hetong/download",{params:{id:id}}).then(res=>{
					if (res.data.result) {
						this.$message.success("下载合同");
					}
				})*/
			},
			edit(id) {
				this.$router.push({path:'/hetong/add',query:{id:id}});
			},
			add() {
				this.$router.push("/hetong/add")
			},
			//列表页数据
			list(){
				//发送ajax请求，根据queryForm查询数据
				this.axios.get(this.$baseUrl+"hetong/getPageInfo",{params:this.queryForm}).then(res=>{
					console.log(res.data);
					this.tableData = res.data.data.list;
				})
			}
		},
		created(){
			this.list();
		}
	}
</script>

<style scoped>

</style>
